package com.ruoyi.system.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.RxDoudianAuthor;
import com.ruoyi.system.mapper.RxDoudianAuthorMapper;
import com.ruoyi.system.service.IRxDoudianAuthorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 直播账号管理Controller
 *
 * @author hjf
 * @date 2025-02-18
 */
@RestController
@RequestMapping("/hmk/author")
public class RxDoudianAuthorController extends BaseController {
    @Autowired
    private IRxDoudianAuthorService rxDoudianAuthorService;

    @Autowired
    private RxDoudianAuthorMapper rxDoudianAuthorMapper;

    /**
     * 查询直播账号管理列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:author:list')")
    @GetMapping("/list")
    public TableDataInfo list(RxDoudianAuthor rxDoudianAuthor) {
        startPage();
        List<RxDoudianAuthor> list = rxDoudianAuthorService.selectRxDoudianAuthorList(rxDoudianAuthor);
        return getDataTable(list);
    }


    /**
     * 下拉列表用
     *
     * @param rxDoudianAuthor
     * @return
     */
    @GetMapping("/simpleList")
    public AjaxResult simpleList(RxDoudianAuthor rxDoudianAuthor) {
        List<RxDoudianAuthor> list = rxDoudianAuthorMapper.selectSimpleRxDoudianAuthorList(rxDoudianAuthor);
        return AjaxResult.success(list);
    }

    /**
     * 导出直播账号管理列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:author:export')")
    //@Log(title = "直播账号管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RxDoudianAuthor rxDoudianAuthor) {
        List<RxDoudianAuthor> list = rxDoudianAuthorService.selectRxDoudianAuthorList(rxDoudianAuthor);
        ExcelUtil<RxDoudianAuthor> util = new ExcelUtil<RxDoudianAuthor>(RxDoudianAuthor.class);
        util.exportExcel(response, list, "直播账号管理数据");
    }

    /**
     * 获取直播账号管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('hmk:author:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(rxDoudianAuthorService.selectRxDoudianAuthorById(id));
    }

    /**
     * 新增直播账号管理
     */
    @PreAuthorize("@ss.hasPermi('hmk:author:add')")
    //@Log(title = "直播账号管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RxDoudianAuthor rxDoudianAuthor) {
        return toAjax(rxDoudianAuthorService.insertRxDoudianAuthor(rxDoudianAuthor));
    }

    /**
     * 修改直播账号管理
     */
    @PreAuthorize("@ss.hasPermi('hmk:author:edit')")
    //@Log(title = "直播账号管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RxDoudianAuthor rxDoudianAuthor) {
        return toAjax(rxDoudianAuthorService.updateRxDoudianAuthor(rxDoudianAuthor));
    }

    /**
     * 删除直播账号管理
     */
    @PreAuthorize("@ss.hasPermi('hmk:author:remove')")
    //@Log(title = "直播账号管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(rxDoudianAuthorService.deleteRxDoudianAuthorByIds(ids));
    }
}
